package com.dl.designmodel.proxy;

import java.lang.reflect.Method;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

/**
 * @ProjectName: mcroservices
 * @Package: com.dl.designmodel.proxy
 * @ClassName: PrayingMantisJdbc
 * @Author: 86977
 * @Description: ${description}
 * @Date: 2021/6/30 17:21
 * @Version: 1.0
 */
public class PrayingMantisCglib implements MethodInterceptor {
  private Cicada cicada;

  public  Cicada getInstance(Cicada cicada){
      this.cicada=cicada;
    Enhancer enhancer=new Enhancer();
    enhancer.setSuperclass(this.cicada.getClass());
    enhancer.setCallback(this);
    return  (Cicada)enhancer.create();
  }

  @Override
  public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

    Object object=methodProxy.invokeSuper(o,objects);
    secondaryMain();
    return object;
  }

  private void secondaryMain(){
    System.out.println("螳螂捕蝉,次要业务");
  }
}
